package serviceGUI;


/*import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;

import commands.SingletonExecute;
import commands.SingletonExecute.LoadCommand;
import commands.SingletonExecute.PaintGUICommand;
import game.GUIManager.Status;*/
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;


public class RemoteControlGUI extends Thread implements ServiceGUI {
	
	private Display display;
	private Shell shell;
	private Button restartButton; 
	private Button pauseButton;
	private Button continueButton;
	private Button stopButton;
	private Canvas canvas;
	
	//private Runnable runnable;
	
	private int width;
	private int height;
	
    
    private static RemoteControlGUI theSingleton = null;
    
    /**
	 * The method requires that the CommandLineInterpreter will create only once.
	 * @return - An reference to CommandLineInterpreter.
	 */
	public static RemoteControlGUI getInstance() {		
		//If this is the first time.
		if(theSingleton == null) {
			//create new object.
			theSingleton = new RemoteControlGUI();
		}//Else - just return the one we already had.
		return theSingleton;
	}
	
	public RemoteControlGUI(){}
	
	public void run(){
		
		display = new Display();
		
		//Create the shell.
		shell = new Shell(display, SWT.CLOSE  | SWT.MIN);
	    shell.setText("Service remote");
	    shell.setSize(230, 70);
	    GridLayout theGridLayout = new GridLayout(1, true);
	    shell.setLayout(theGridLayout);
	    
	    //Create a composite with 1 row and 4 columns.
	    Composite composite = new Composite(shell, SWT.NONE);
	    GridData data = new GridData(GridData.FILL_HORIZONTAL);
	    data.horizontalSpan = 1;
	    composite.setLayoutData(data);
	    GridLayout layout = new GridLayout();
	    layout.numColumns = 4;
	    composite.setLayout(layout);
	    
	    //Create the button 'Restart'.
	    restartButton = new Button(composite, SWT.PUSH);
	    restartButton.setText("Restart");
	    restartButton.setLayoutData(new GridData());
	    restartButton.setEnabled(false);
	    
	    //Create the button 'Pause'.
	    pauseButton = new Button(composite, SWT.PUSH);
	    pauseButton.setText("Pause");
	    pauseButton.setLayoutData(new GridData());
	    
	    //Create the button 'Continue'.
	    continueButton = new Button(composite, SWT.PUSH);
	    continueButton.setText("Continue");
	    continueButton.setLayoutData(new GridData());
	    continueButton.setEnabled(false);
	    
	    //Create the button 'Stop'.
	    stopButton = new Button(composite, SWT.PUSH);
	    stopButton.setText("Stop");
	    stopButton.setLayoutData(new GridData());
	 	
	    
	    
		//Add a listener selection to the restartButton to restart the service.
		restartButton.addSelectionListener(new SelectionListener() {

			@Override
			public void widgetSelected(SelectionEvent arg0) {
			
				//Set the enabled of the buttons.
				restartButton.setEnabled(false);
				pauseButton.setEnabled(true);
				continueButton.setEnabled(false);
				stopButton.setEnabled(true);
							
			}

			@Override
			public void widgetDefaultSelected(SelectionEvent arg0) {
			}
		});
		
		//Add a listener selection to the pauseButton to pause the service.
		pauseButton.addSelectionListener(new SelectionListener() {

			@Override
			public void widgetSelected(SelectionEvent arg0) {
				//Set the enabled of the buttons.
				restartButton.setEnabled(false);
				pauseButton.setEnabled(false);
				continueButton.setEnabled(true);
				stopButton.setEnabled(false);
				
			}

			@Override
			public void widgetDefaultSelected(SelectionEvent arg0) {
			}
		});
		
		//Add a listener selection to the continueButton to continue the service.
		continueButton.addSelectionListener(new SelectionListener() {

			@Override
			public void widgetSelected(SelectionEvent arg0) {
				
				//Set the enabled of the buttons.
				restartButton.setEnabled(false);
				pauseButton.setEnabled(true);
				continueButton.setEnabled(false);
				stopButton.setEnabled(true);
				
			}

			@Override
			public void widgetDefaultSelected(SelectionEvent arg0) {
			}
		});

		//Add a listener selection to the stopButton to stop the service.
		stopButton.addSelectionListener(new SelectionListener() {

			@Override
			public void widgetSelected(SelectionEvent arg0) {
				
				//Set the enabled of the buttons.
				restartButton.setEnabled(true);
				pauseButton.setEnabled(false);
				continueButton.setEnabled(false);
				stopButton.setEnabled(false);
			}

			@Override
			public void widgetDefaultSelected(SelectionEvent arg0) {
			}
		});

		

		//Create a runnable that redraw the simulation.
	/*	runnable=new Runnable() {
            public void run() {
                display.timerExec(1000/(int)hz , this);
                canvas.redraw();
                }
            };
            
        //Get the status of the simulation.
        status=theManagGui.getStatusSimul();
		
        //Update the GUI according to the status of the simulation.  
		switch (status) {
		case START:
					simulStart();
					break;
		case PAUSE:
					simulPause();
					break;
		case CONTINUE:
					simulContinue();
					break;
		case STOP:
					simulStop();
					break;
		default:
					break;
		}*/
            

		//Open the shell.
	    shell.open();
	    //Set up the event loop.
	    while (!shell.isDisposed()) {
	      if (!display.readAndDispatch()) {
	        //If no more entries in the event queue.
	        display.sleep();
	      }
	    }
	    
		//Execute the command to close the GUI.
	/*	theSinglExecuter.getCloseGUIExecutor().execute();
		display.dispose(); 
	}*/
	
	
	/**
	 * The method will update the buttons of the GUI when the simulation is start.
	 */
	/*public void simulStart(){
		display.syncExec(new Runnable() {
            public void run() {
            	//Update the status of the simulation.
            	status=theManagGui.getStatusSimul();
        		//Set the enable of the buttons
        		restartButton.setEnabled(false);
        		pauseButton.setEnabled(true);
        		continueButton.setEnabled(false);
        		stopButton.setEnabled(true);
        		//Redraw the GUI according to the runnable and the hz.
        		display.timerExec((int)hz, runnable);
            }
        });
	}*/
	
	/**
	 * The method will update the buttons of the GUI when the simulation is pause.
	 */
	/*public void simulPause(){
		display.syncExec(new Runnable() {
            public void run() {
            	//Update the status of the simulation.
            	status=theManagGui.getStatusSimul();
        		//Set the enable of the buttons
            	restartButton.setEnabled(false);
				pauseButton.setEnabled(false);
				continueButton.setEnabled(true);
				stopButton.setEnabled(false);
				//Stop to redraw the GUI according to the runnable and the hz=-1.
				display.timerExec(-1, runnable);
            }
        });
	}*/

	/**
	 * The method will update the buttons of the GUI when the simulation is continue.
	 */
	/*public void simulContinue(){
		display.syncExec(new Runnable() {
            public void run() {
            	//Update the status of the simulation.
            	status=theManagGui.getStatusSimul();
            	//Set the enable of the buttons
				restartButton.setEnabled(false);
				pauseButton.setEnabled(true);
				continueButton.setEnabled(false);
				stopButton.setEnabled(true);
				//If there is foods to pickup
				if(!noMoreFood)
					//Redraw the GUI according to the runnable and the hz.
					display.timerExec((int)hz, runnable);
				//If there is no more foods to pickup.
				else
					//Stop to redraw the GUI according to the runnable and the hz=-1.
					display.timerExec(-1, runnable);
            }
        });
	}*/
	
	/**
	 * The method will update the buttons of the GUI when the simulation is stop.
	 */
	/*public void simulStop(){
		display.syncExec(new Runnable() {
            public void run() {
            	//Update the status of the simulation.
            	status=theManagGui.getStatusSimul();
            	//Set the enable of the buttons
				restartButton.setEnabled(true);
				pauseButton.setEnabled(false);
				continueButton.setEnabled(false);
				stopButton.setEnabled(false);
				//Stop to redraw the GUI according to the runnable and the hz=-1.
				display.timerExec(-1, runnable);
            }
        });
	}*/
	
	/**
	 * The method will update the data of the GUI after the simulation load a file.
	 */
/*	public void simulLoad(){
		display.syncExec(new Runnable() {
            public void run() {
            	height=theManagGui.getHeightSimul();
            	width=theManagGui.getWidthSimul();
            	hz=theManagGui.getHzSimul();
            	//Update the size of the shell.
            	shell.setSize(width+40, height+100);
            }
        });
	}*/
	
	/**
	 * The method will redraw the GUI after the simulation get a new forager.
	 */
/*	public void simulInitForager(){
		display.syncExec(new Runnable() {
            public void run() {
            	canvas.redraw();
            }
        });
	}*/
	
	/**
	 * The method will redraw the GUI after the simulation get a new food.
	 */
/*	public void simulInitFood(){
		display.syncExec(new Runnable() {
            public void run() {
            	noMoreFood=false;
            	//If the simulation got a new food and the simulation is started/continued,
            	//the foragers can pick it up and the GUI need to redraw that. 
            	if(status==Status.START || status==Status.CONTINUE)
            		display.timerExec((int)hz, runnable);
            	//If the simulation is stoped/paused, only redraw one time the food.
            	else
            		canvas.redraw();
            }
        });
	}*/
	
	/**
	 * The method will stop the redraw of the GUI if there is no more foods to pickup.
	 */
/*	public void simulNoFoods(){
		display.syncExec(new Runnable() {
            public void run() {
            	noMoreFood=true;
            	//Stop to redraw the GUI according to the runnable and the hz=-1.
            	display.timerExec(-1, runnable);
            }
        });
	}*/
	
	/**
	 * The method will close the GUI.
	 */
/*	public void closeGUI(){
		display.syncExec(new Runnable() {
            public void run() {
            	theSingleton=null;
            	if (!shell.isDisposed())
            		shell.dispose();
            }
        });*/
	    
	 /*   shell.open();
	    //Set up the event loop.
	    while (!shell.isDisposed()) {
	      if (!display.readAndDispatch()) {
	        //If no more entries in the event queue
	        display.sleep();
	      }
	    }*/
	    
	}


}
